<template>
  <div class="deal-product-card">
    <!-- 左产品图 -->
    <div class="produvt-image-container">
      <img :src="product.image" 
        alt="产品图"
        class="product-img">
    </div>
    <!-- 右详情信息 -->
     <div class="product-info">
      <!-- 星级评分 -->
      <div class="rating">
        <span v-for="n in 5" 
        :key="n" 
        :style="{color: n <= 4 ? '#BEAE59' : '#ccc'}">★</span>
      </div>
      <!-- 标题，标签 -->
       <h3 class="product-title" style="font-size: 25px;">{{ product.title }}</h3>
       <p class="product-desc">{{ product.desc }}</p>
       <div class="price-wrap" v-if="product && product.oldPrice">
        <span class="original-price" v-if="product.oldPrice">
          ${{ product.oldPrice }}
        </span>
        <span class="current-price" style="font-size: 30px;">
          ${{ product.price }}
        </span>
       </div>
       <div class="hover-effect">
      <div class="actions" >
        <button><ShoppingBag /></button>
        <button><HeartOutlined /></button>
        <button><SyncOutlined /></button>
        <button><SearchOutlined /></button>
      </div>
    </div>
     </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { SearchOutlined, SyncOutlined, HeartOutlined } from '@ant-design/icons-vue';
import { ShoppingBag } from '@element-plus/icons-vue'

const props = defineProps({
  product: {
    type:Object,
    required:true,
    default: () => ({})
  }
});
const hasOldPrice = computed(() => props.product && 'oldPrice' in props.product);

// 控制悬停状态
const handleHover = () => isHover.value = true
const handleLeave = () => isHover.value = false
</script>

<style scoped>
.deal-product-card{
  display: flex;
  width: 100%;
  height: 100%;
  max-width: 800px; 
  margin: 0 auto;    /* 居中显示 */
}
.product-image-container{
  width: 50% ;
  height: 300px;
}
.product-img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.7s;
  &:hover { 
    transform: scale(1.1);
  }
}

/* ==========产品信息区域 ==========*/

.product-info{
  width: 50%;
  padding: 30px 0 0 30px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}
.rating{
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 6px;
  text-align: left;
}
.price-wrap{
  display: flex;
  align-items: center;
}
.product-title {
  font-size: 24px;
  font-weight: 800;
  color: #333;
  margin-top: 10px; /* 标题下移 */
  margin-bottom: 15px;
  text-align: left; /* 左对齐 */
}
.product-desc {
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
  text-align: left; 
}
.original-price{
  text-decoration: line-through;
  color: #999;
  margin-right: 10px;
  font-size: 20px;
}
.current-price {
  font-weight: bold;
  color: #beae59;
}

/* ===============悬停按钮============== */
/* 悬停按钮容器 */
.hover-effect {
  position: relative;
  height: 40px; /* 给固定高度，让按钮有定位参考 */
}
/* 悬停时显示的操作按钮 */
.actions {
  position: absolute;
  bottom: -10px; /* 按钮距离卡片底部10px */
  left: 0;
  display: flex;
  gap: 13px; /* 按钮之间的间距 */
  opacity: 0;
  transition: all 0.3s ease;
}
.deal-product-card:hover .actions {
  opacity: 1;
  bottom:1px; /* 按钮移到卡片内 */
}
.actions button {
  width: 30px;        
  height: 30px;       
  border-radius: 50%; 
  padding: 0;         
  display: flex;     
  align-items: center;
  justify-content: center; 
  background: #DCDCDC;
  border: 1px solid #ddd;
  cursor: pointer;
  transition: all 0.3s ease;
}
/* 对购物袋按钮调整 */
.actions button svg {
  width: 16px !important; 
  height: 16px !important;
  stroke-width: 1.2px !important;
  transform: scale(1) !important; 
}
.actions button:first-child svg {
  stroke-width: 1px !important; 
}
</style>